<?php

namespace App\Http\Middleware;

use App\Datalog\RequestLog;
use Closure;
use Illuminate\Http\Request;

class RequestCheck
{
    // 研发调用-允许访问的路由
    protected $roleList = [
        '/api/ad/monitor',
    ];

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        // header('Access-Control-Allow-Origin: *');
        // header('Access-Control-Allow-Headers: x-requested-with,content-type');
        // header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, OPTIONS');
        // header('Access-Control-Allow-Credentials: false');

        $uri = $request->getPathInfo();
        if (!in_array($uri, $this->roleList)) {
            RequestLog::getInstance()->addLog();
        }

        return $next($request);
    }
}
